package com.alibaba.citrus.cr.unified.inventory.functions.handler;

import com.alibaba.citrus.cr.unified.inventory.model.AllocateOrderEntity;
import com.alibaba.cz.base.tool.Nullable;
import com.epoch.app.crunifiedinventory.domain.allocateorder.model.AllocateOrder;
import com.epoch.app.crunifiedinventory.domain.allocateorderdetail.model.AllocateOrderDetail;

import java.util.List;

/**
 * @description:
 * @author: yuhw
 * @date: 2024年01月22日 21:41
 **/
public interface AllocateOrderStatusHandler {

    String getType();

    default void execute(AllocateOrderEntity allocateOrderEntity){
        //是否是计划调拨单货场仓收货
        boolean freightYardReceive = isFreightYardReceive(allocateOrderEntity.getAllocateOrder());
        Nullable.stream(allocateOrderEntity.getDetailList()).forEach(detail -> process(detail,freightYardReceive));
        //更新主单
        process(allocateOrderEntity.getAllocateOrder(),allocateOrderEntity.getDetailList(),freightYardReceive);
    }

    /**
     * 更新主单
     * @param allocateOrder
     */
    void process(AllocateOrder allocateOrder, List<AllocateOrderDetail> detailList, boolean isFreightYardReceive);

    /**
     * 更新子单
     * @param allocateOrderDetail
     */
    void process(AllocateOrderDetail allocateOrderDetail,boolean isFreightYardReceive);

    /**
     * 是否是计划调拨单货场仓收货
     * @return
     */
    default boolean isFreightYardReceive(AllocateOrder allocateOrder){
        return false;
    }

}
